package com.ruoyi.bus.controller.front;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.bus.domain.TransUnit;
import com.ruoyi.bus.domain.WlInfoVo;
import com.ruoyi.bus.service.ITransUnitService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.kuaidi.KdNiao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/api/searchWl")
public class WlSearch {
    @Autowired
    private ITransUnitService transUnitService;

    @RequestMapping("/wlInfo")
    @ResponseBody
    public AjaxResult getWlInfoByTransId(String expCode,String expNo){
        KdNiao api = new KdNiao();
        try {
            String result = api.getOrderTracesByJson(expCode, expNo);
            WlInfoVo wlInfoVo= JSON.parseObject(result,WlInfoVo.class);
            TransUnit unit=transUnitService.getOne(new QueryWrapper<>(new TransUnit().setTransCode(expCode)));
            if(unit!=null){
                wlInfoVo.setTransName(unit.getTransName());
            }
            return AjaxResult.success(wlInfoVo);

        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error();
        }

    }

   /* public String getWlInfoByTransId(){
        KdniaoTrackQueryAPI api = new KdniaoTrackQueryAPI();
        try {
            String result = api.getOrderTracesByJson("ANE", "210001633605");
            System.out.print(result);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }*/


    public static void main(String[] args) {
        KdNiao api = new KdNiao();
        try {
            String result = api.getOrderTracesByJson("ZTO", "77111270589811");
            System.out.println(result);
            WlInfoVo wlInfoVo= JSON.parseObject(result,WlInfoVo.class);
            System.out.println(wlInfoVo);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
